﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Attendance.Model;

namespace EzDesk.Attendance.AttendanceImpl.Filters
{
    public static class LeaveInfoFilter
    {
        /// <summary>
        /// 筛选出时间段内的假期
        /// </summary>
        /// <param name="query"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public static IQueryable<LeaveInfo> BetweenTwoDays(this IQueryable<LeaveInfo> query, DateTime? startDate, DateTime? endDate)
        {          
            if (startDate.HasValue)
            {
                query = query.Where(q => q.EndTime > startDate.GetValueOrDefault().Date);
            }
            if (endDate.HasValue)
            {
                var dayAfterEndDate = endDate.GetValueOrDefault().AddDays(1);
                query = query.Where(q => q.StartTime < dayAfterEndDate.Date);
            }
            return query;
        }

        public static IQueryable<LeaveInfo> ByUserId(this IQueryable<LeaveInfo> query, Guid userId)
        {
            return query.Where(q => q.UserId ==userId);
        }

        public static IQueryable<LeaveInfo> ByLeaveId(this IQueryable<LeaveInfo> query, Guid leaveId)
        {
            return query.Where(q => q.LeaveId == leaveId);
        }
    }
}
